/**
 * Two methods implemented here.
 * 1st, use one for loop to count the occurrence of each answer, 'A', 'B', 'C', etc.
 * 		use another to assign the value to return array based on those three counters.
 * 
 * 2nd, just use one loop, generate the substring for index,
 * 		then, check if those letters existence.
 * 	PS: if String.contains function take equal or more than linear time, 
 * 		the second solution is no good.
 */

/**
 * @author antonio081014
 * @since Dec 13, 2011, 10:14:33 PM
 */

public class CheatingQuiz {
	public int[] howMany(String answers) {
		int[] ret = new int[answers.length()];
		int A = 0;
		int B = 0;
		int C = 0;

		for (int i = 0; i < answers.length(); i++) {
			if (answers.charAt(i) == 'A')
				A++;
			else if (answers.charAt(i) == 'B')
				B++;
			else if (answers.charAt(i) == 'C')
				C++;
		}
		int count = (A > 0 ? 1 : 0) + (B > 0 ? 1 : 0) + (C > 0 ? 1 : 0);
		for (int i = 0; i < answers.length(); i++) {
			ret[i] = count;
			if (answers.charAt(i) == 'A') {
				A--;
			} else if (answers.charAt(i) == 'B') {
				B--;
			} else if (answers.charAt(i) == 'C') {
				C--;
			}
			count = (A > 0 ? 1 : 0) + (B > 0 ? 1 : 0) + (C > 0 ? 1 : 0);
		}
		return ret;
	}

	public int[] sovle(String ans) {
		int N = ans.length();
		int[] ret = new int[N];
		for (int i = 0; i < N; i++) {
			String tmp = ans.substring(i);
			int count = (tmp.contains("A") ? 1 : 0)
					+ (tmp.contains("B") ? 1 : 0) + (tmp.contains("C") ? 1 : 0);
			ret[i] = count;
		}
		return ret;
	}
	// <%:testing-code%>
}
// Powered by [KawigiEdit] 2.0!
